package io.yunho.yunho.interview.two.juc;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by Administrator on 2020/4/13.
 *  CAS是什么？ ===>compareAndSwap
 *     比较并交换
 */
public class CASDemo {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(1);
        System.out.println(atomicInteger.compareAndSet(1,2020)+"\t 当前值："+atomicInteger.get());
        System.out.println(atomicInteger.compareAndSet(1,2030)+"\t 当前值："+atomicInteger.get());
        atomicInteger.getAndIncrement();
        System.out.println("\t 当前值："+atomicInteger.get());
    }
}
